package com.nondo.dean.dealer.controller.api.inner;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.nondo.dean.dealer.domain.Store;
import com.nondo.dean.dealer.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.nondo.dean.common.annotation.ApiVersion;
import com.nondo.dean.common.web.View;
import com.nondo.dean.dealer.model.OrderDetailBean;
import com.nondo.dean.dealer.service.StoreProductService;

/**
 * 店铺管理内部接口
 * @author zhaolijin
 * @date 2018年4月26日
 */
@RestController("apiInnerDealerStore")
@RequestMapping("/{v}/inner/store")
public class StoreController {
    
    @Autowired
    StoreProductService storeProductService;

    @Autowired
    StoreService storeService;


    /**
     * 将采购产品写入店铺产品
     * @param request
     * @param response
     * @param storeId 店铺ID
     * @param orderDetailList 采购产品列表
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/{storeId}/product/save")
    public View<Integer> save(HttpServletRequest request, HttpServletResponse response,@PathVariable Integer storeId, @RequestBody List<OrderDetailBean> orderDetailList) {
        View<Integer> view = new View<Integer>(20000, "更新成功");
        int num = storeProductService.savePurchaseProduct(storeId, orderDetailList);
        view.setData(num);
        return view;
    }

    /**
     * 根据主键ID查询店铺名称
     * @param request
     * @param response
     * @param id
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/select/{id}")
    public View<String> select(HttpServletRequest request, HttpServletResponse response,@PathVariable("id") Integer id) {
        View<String> view = new View<String>(20000, "查询成功");
        Store store = storeService.select(id);
        view.setData(store.getName());
        return view;
    }
}
